﻿/*
    File Name:      uknow_url_mapping.js
    Created By:     victor.liu
    Created When:   2012-03-05
    Created Whys:   This js file is created mainly for url mapping on static html page
*/

var mapping_array = [
    "aboutuknow.html",
    "events.html",
    "uknow_co_edu.html",
    "aboutbc.html",
    "eventcalendar.html",
    "interactivespace.aspx",
    "introduction.html",
    "winners.html",
    "sponsors.html",
    "brunswick.html",
    "burberry.html",
    "diagoe.html",
    "hsbc.html",
    "ihg.html",
    "jlr.html",
    "nortonrose.html",
    "prudential.html",
    "standardchartered.html",
    "swire.html",
    "ielts.html",
    "sponsoruknow.aspx"
];

function existedInMapping(location) {
    var url = location.href;
    var lastIndex = url.lastIndexOf("/");
    var pageName = url.substr(lastIndex + 1);
    var length = mapping_array.length;
    for (var i = 0; i < length; i++) {
        if (pageName.toLowerCase() == mapping_array[i]) {
            return mapping_array[i];
        }
    }

    return null;
}

function cnenlink() {
    var hdn = document.getElementById("hdn_eventsId");
    if (hdn) {
        var evid = $("#hdn_eventsId").val();
        $.post("/CnEnMapp.aspx",
            { lanid: "2052", eventid: evid },
            function (data) {
                if (data != "error" && data.toString() != "0") {
                    $("#toenlink").attr("href", "/en/events/" + data + ".html");
                }
                else {
                    $("#toenlink").attr("href", "/en/eventcalendar.html");
                }
            });
    }
    else {
        var mappingUrl = existedInMapping(location);
        if (mappingUrl != null) {
            $("#toenlink").attr("href", location.href.replace("/cn/", "/en/"));
        }
    }
}

function encnlink() {
    var hdn = document.getElementById("hdn_eventsId");
    if (hdn) {
        var evid = $("#hdn_eventsId").val();
        $.post("/CnEnMapp.aspx", { lanid: "1033", eventid: evid },
            function (data) {
                if (data != "error" && data.toString() != "0") {
                    $("#toenlink").attr("href", "/cn/events/" + data + ".html");
                }
                else {
                    $("#toenlink").attr("href", "/cn/eventcalendar.html");
                }
            }
        );
    } else {
        var mappingUrl = existedInMapping(location);
        if (mappingUrl != null) {
            $("#toenlink").attr("href", location.href.replace("/en/", "/cn/"));
        }
    }
}
